'''
定义函数 def 函数名称(形参):
            逻辑代码
            return 返回值 #有返回值 无返回值不用写return
函数不调用不执行  调用的时候需要给定函数中需要的实参

'''
import pymysql


def mySort(xlist):
    # xlist = [123, 423213, 1, 23, 42, 23, 2, 3, 4, 5, 340, 342]
    for i in range(0, len(xlist) - 1):
        for j in range(0, len(xlist) - 1 - i):
            if xlist[j] > xlist[j + 1]:
                xlist[j], xlist[j + 1] = xlist[j + 1], xlist[j]
    print(xlist)

def add(a,b):
    print(a+b)

def add1(a,b):
    return a+b

#调用函数
add(10,20)
num = add1(10,120)
print(num)

# 却省参数 默认值参数
def login(password,username="admin"):
    if username == "admin" and password == "admin":
        return {"status":200,"msg":"登陆成共"}
    else:
        return {"status": 400, "msg": "错误"}
print(login("admin","admin"))
print(login("admin",))

slist = [123, 423213, 1, 23, 42, 23, 2, 3, 4, 5, 340, 342]
print(mySort(slist))
# 可变参数
def add(*args):   # args是元组 调用函数的多个参数会组成一个赋值给args
    sum = 0
    for a in args:
        sum += a
    return sum
result = add(1,2,3,4,2,2)
print(result)



#作业练习


#字典可变参数
def login1(**kwargs):
    print(kwargs)

login1(username="admin",password="123")

# open(file="1.txt",mode="w",encoding="utf-8")
# pymysql.connect()

resp = login("admin","admin")
if 200 == resp["status"]:
    print(resp["msg"])

x = 1000

def funA():
    a = 100
    print(x)
def funB():
    b = 200
    print(x)
    # global x
    # x = 999
    # print(x)



# if __name__ == '__main__':